/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ReversiGUI.java
 *
 * Created on 09-nov-2011, 21:51:25
 */
package example_reversi;

import java.awt.Color;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import java.util.LinkedList;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import utils.Pair;

/**
 *
 * @author BigEma
 */
public class ReversiGUI extends javax.swing.JFrame implements ActionListener, MouseListener {
    private static final long serialVersionUID = 1L;
    private ReversiController controller;
    private List<Pair<Integer,Integer>> currentAvailableMoves = new LinkedList<Pair<Integer,Integer>>();
    private ReversiBoardRenderer render;

    /** Creates new form ReversiGUI */
    public ReversiGUI() {}
    
    public void setController(ReversiController controller) {
        this.controller = controller;
    }
    
    public ReversiBoardRenderer getRender() {
        return this.render;
    }
    
    public void init() {
        render = new ReversiBoardRenderer();
        initComponents();
        this.setVisible(true);
        this.setEnabled(true);
        this.board.setEnabled(false);
        this.paintDisabledBoard();
        this.setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        player1Name = new javax.swing.JLabel();
        player1Color = new javax.swing.JLabel();
        player1Count = new javax.swing.JLabel();
        player2Name = new javax.swing.JLabel();
        player2Color = new javax.swing.JLabel();
        player2Count = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        board = new javax.swing.JTable();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        newGameMenuItem = new javax.swing.JMenuItem();
        stopGameMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        settingsMenu = new javax.swing.JMenu();
        settingsMenuItem = new javax.swing.JMenuItem();
        aiMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        aboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setResizable(false);

        player1Name.setText("jugador1");

        player1Color.setText("color");

        player1Count.setText("XXX");

        player2Name.setText("jugador2");

        player2Color.setText("color");

        player2Count.setText("XXX");

        board.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "", "", "", "", "", "", "", ""
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        board.setDefaultRenderer(Integer.class, this.render);
        board.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        board.setAutoscrolls(false);
        board.setColumnSelectionAllowed(true);
        board.setDoubleBuffered(true);
        board.setFillsViewportHeight(true);
        board.setOpaque(false);
        board.setRowHeight(32);
        board.setRowSelectionAllowed(false);
        board.setShowHorizontalLines(false);
        board.setShowVerticalLines(false);
        board.addMouseListener(this);
        jScrollPane1.setViewportView(board);
        board.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        board.getColumnModel().getColumn(0).setMinWidth(32);
        board.getColumnModel().getColumn(0).setPreferredWidth(32);
        board.getColumnModel().getColumn(0).setMaxWidth(32);
        board.getColumnModel().getColumn(1).setMinWidth(32);
        board.getColumnModel().getColumn(1).setPreferredWidth(32);
        board.getColumnModel().getColumn(1).setMaxWidth(32);
        board.getColumnModel().getColumn(2).setMinWidth(32);
        board.getColumnModel().getColumn(2).setPreferredWidth(32);
        board.getColumnModel().getColumn(2).setMaxWidth(32);
        board.getColumnModel().getColumn(3).setMinWidth(32);
        board.getColumnModel().getColumn(3).setPreferredWidth(32);
        board.getColumnModel().getColumn(3).setMaxWidth(32);
        board.getColumnModel().getColumn(4).setMinWidth(32);
        board.getColumnModel().getColumn(4).setPreferredWidth(32);
        board.getColumnModel().getColumn(4).setMaxWidth(32);
        board.getColumnModel().getColumn(5).setMinWidth(32);
        board.getColumnModel().getColumn(5).setPreferredWidth(32);
        board.getColumnModel().getColumn(5).setMaxWidth(32);
        board.getColumnModel().getColumn(6).setMinWidth(32);
        board.getColumnModel().getColumn(6).setPreferredWidth(32);
        board.getColumnModel().getColumn(6).setMaxWidth(32);
        board.getColumnModel().getColumn(7).setMinWidth(32);
        board.getColumnModel().getColumn(7).setPreferredWidth(32);
        board.getColumnModel().getColumn(7).setMaxWidth(32);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(player1Name, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(player2Name, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(player1Color)
                            .addComponent(player2Color))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(player1Count)
                            .addComponent(player2Count))))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(player1Name)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(player2Name))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addComponent(player2Color))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(player1Color)
                            .addComponent(player1Count))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(player2Count)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        fileMenu.setMnemonic('R');
        fileMenu.setText("Reversi");

        newGameMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        newGameMenuItem.setMnemonic('n');
        newGameMenuItem.setText("Nuevo");
        newGameMenuItem.addActionListener(this);
        fileMenu.add(newGameMenuItem);

        stopGameMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        stopGameMenuItem.setMnemonic('s');
        stopGameMenuItem.setText("Detener");
        stopGameMenuItem.addActionListener(this);
        fileMenu.add(stopGameMenuItem);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Salir");
        exitMenuItem.addActionListener(this);
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        settingsMenu.setMnemonic('S');
        settingsMenu.setText("Preferencias");

        settingsMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_MASK));
        settingsMenuItem.setMnemonic('e');
        settingsMenuItem.setText("Preferencias");
        settingsMenuItem.addActionListener(this);
        settingsMenu.add(settingsMenuItem);

        aiMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_MASK));
        aiMenuItem.setMnemonic('i');
        aiMenuItem.setText("IA");
        aiMenuItem.addActionListener(this);
        settingsMenu.add(aiMenuItem);

        menuBar.add(settingsMenu);

        helpMenu.setMnemonic('H');
        helpMenu.setText("Ayuda");

        aboutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.SHIFT_MASK));
        aboutMenuItem.setMnemonic('a');
        aboutMenuItem.setText("Acerca de");
        aboutMenuItem.addActionListener(this);
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }

    // Code for dispatching events from components to event handlers.

    public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (evt.getSource() == newGameMenuItem) {
            ReversiGUI.this.newGameMenuItemActionPerformed(evt);
        }
        else if (evt.getSource() == stopGameMenuItem) {
            ReversiGUI.this.stopGameMenuItemActionPerformed(evt);
        }
        else if (evt.getSource() == exitMenuItem) {
            ReversiGUI.this.exitMenuItemActionPerformed(evt);
        }
        else if (evt.getSource() == settingsMenuItem) {
            ReversiGUI.this.settingsMenuItemActionPerformed(evt);
        }
        else if (evt.getSource() == aiMenuItem) {
            ReversiGUI.this.aiMenuItemActionPerformed(evt);
        }
        else if (evt.getSource() == aboutMenuItem) {
            ReversiGUI.this.aboutMenuItemActionPerformed(evt);
        }
    }

    public void mouseClicked(java.awt.event.MouseEvent evt) {
    }

    public void mouseEntered(java.awt.event.MouseEvent evt) {
    }

    public void mouseExited(java.awt.event.MouseEvent evt) {
    }

    public void mousePressed(java.awt.event.MouseEvent evt) {
    }

    public void mouseReleased(java.awt.event.MouseEvent evt) {
        if (evt.getSource() == board) {
            ReversiGUI.this.boardMouseReleased(evt);
        }
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        this.controller.exitGame();
    }//GEN-LAST:event_exitMenuItemActionPerformed

    
    private void boardMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_boardMouseReleased
        int row = this.board.rowAtPoint(evt.getPoint());
        int col = this.board.columnAtPoint(evt.getPoint());
        boolean enabled = (Integer)this.board.getValueAt(row, col) == Integer.MAX_VALUE || (Integer)this.board.getValueAt(row, col) == Integer.MIN_VALUE;
        if (enabled) this.controller.placeToken(row, col);
    }//GEN-LAST:event_boardMouseReleased

    private void newGameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newGameMenuItemActionPerformed
        this.controller.newGame();
    }//GEN-LAST:event_newGameMenuItemActionPerformed

    private void settingsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsMenuItemActionPerformed
        this.controller.settings();
    }//GEN-LAST:event_settingsMenuItemActionPerformed

    private void aiMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aiMenuItemActionPerformed
        this.controller.iaSettings();
    }//GEN-LAST:event_aiMenuItemActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
        this.controller.about();
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void stopGameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopGameMenuItemActionPerformed
        this.board.setEnabled(false);
        this.board.setVisible(false);
        this.controller.endGame();
    }//GEN-LAST:event_stopGameMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /* Set the Nimbus look and feel */
//        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
//        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
//         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(ReversiGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(ReversiGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(ReversiGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(ReversiGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>
//
////        /* Create and display the form */
////        java.awt.EventQueue.invokeLater(new Runnable() {
////
////            public void run() {
////                new ReversiGUI().setVisible(true);
////            }
////        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JMenuItem aiMenuItem;
    private javax.swing.JTable board;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem newGameMenuItem;
    private javax.swing.JLabel player1Color;
    private javax.swing.JLabel player1Count;
    private javax.swing.JLabel player1Name;
    private javax.swing.JLabel player2Color;
    private javax.swing.JLabel player2Count;
    private javax.swing.JLabel player2Name;
    private javax.swing.JMenu settingsMenu;
    private javax.swing.JMenuItem settingsMenuItem;
    private javax.swing.JMenuItem stopGameMenuItem;
    // End of variables declaration//GEN-END:variables

    public JLabel getPlayer1Color() {
        return player1Color;
    }

    public JLabel getPlayer1Name() {
        return player1Name;
    }

    public JLabel getPlayer2Color() {
        return player2Color;
    }

    public JLabel getPlayer2Name() {
        return player2Name;
    }
    
    public void enableBoard() {
        this.board.setEnabled(true);
        this.board.setVisible(true);
    }
    
    public void enableBoardInteraction(boolean enable) {
        this.board.setEnabled(enable);
    }
    
    public void paintDisabledBoard() {
        for (int row = 0; row < 8; row++) {
            for (int col = 0; col < 8; col++) {
                this.board.setValueAt(0, row, col);
            }
        }
    }
    
    public void repaintBoard() {
        this.board.repaint();
    }
    
    public void update(ReversiState model) {
        for (Pair<Integer,Integer> oldAvailableMove:currentAvailableMoves) {
            this.board.setValueAt(0, oldAvailableMove.getFirstElem(), oldAvailableMove.getSecondElem());
        }
        for (int row = 0; row < 8; row++) {
            for (int col = 0; col < 8; col++) {
                this.board.setValueAt(model.getColorAt(row, col), row, col);
            }
        }
        int enabledCellColor = model.isMax()?Integer.MAX_VALUE:Integer.MIN_VALUE;
        if (model.isMax()) {
            currentAvailableMoves = model.whiteAvailableMoves;
        } else {
            currentAvailableMoves = model.blackAvailableMoves;
        }
        if (currentAvailableMoves != null) {
            for (Pair<Integer,Integer> availableMove:currentAvailableMoves) {
                this.board.setValueAt(enabledCellColor, availableMove.getFirstElem(), availableMove.getSecondElem());
            }
        }
        this.player1Count.setText(Integer.toString(getPlayer1Color().getText().compareToIgnoreCase("white") == 0?model.getWhiteCount():model.getBlackCount()));
        this.player2Count.setText(Integer.toString(getPlayer2Color().getText().compareToIgnoreCase("white") == 0?model.getWhiteCount():model.getBlackCount()));
        getPlayer1Color().setForeground(null);
        getPlayer2Color().setForeground(null);
        if (model.isMax()) {
            if (getPlayer1Color().getText().compareToIgnoreCase("white")==0) {
                //le toca al jugador 1
                getPlayer1Color().setForeground(Color.blue);
            } else {
                //le toca al jugador 2
                getPlayer2Color().setForeground(Color.blue);
            }
            
        } else {
            if (getPlayer1Color().getText().compareToIgnoreCase("black")==0) {
                //le toca al jugador 1
                getPlayer1Color().setForeground(Color.blue);
            } else {
                //le toca al jugador 2
                getPlayer2Color().setForeground(Color.blue);
            }
        }
        this.board.updateUI();
        if (this.controller.getLogic().getModel().gameIsOver()) {
            if (model.maxWins()) {
                this.gameResults(true, false);
            } else if (model.minWins()) {
                this.gameResults(false,true);
            } else {
                this.gameResults(true, true);
            }
                this.controller.endGame();
        }
    }
    
    private void gameResults(boolean maxWon, boolean minWon) {
        ReversiLogic logic = this.controller.getLogic();
        boolean singlePlayer = logic.getModel().getPlayersBrains()[0] ^ logic.getModel().getPlayersBrains()[1];
        int player = singlePlayer?!logic.getModel().getPlayersBrains()[0]?0:1:-1;
        EndGameDialog endGameDialog;
        if (maxWon && minWon) {
            endGameDialog = new EndGameDialog(new ImageIcon(System.class.getResource("/images/empataste120x120.jpg")),"EMPATARON!!!");
        } else {
            if (singlePlayer) {
                if (maxWon && logic.getModel().getPlayersColors()[player] == ReversiToken.WHITE) {
                    endGameDialog = new EndGameDialog(new ImageIcon(System.class.getResource("/images/ganaste120x120.jpg")),"GANASTE!!!");
                } else if (minWon && logic.getModel().getPlayersColors()[player] == ReversiToken.BLACK) {
                    endGameDialog = new EndGameDialog(new ImageIcon(System.class.getResource("/images/ganaste120x120.jpg")),"GANASTE!!!");
                } else {
                    endGameDialog = new EndGameDialog(new ImageIcon(System.class.getResource("/images/perdiste120x120.jpg")),"PERDISTE!!!");
                }
            } else {
                if (maxWon) {
                    if (logic.getModel().getPlayersColors()[0]==ReversiToken.WHITE) {
                        endGameDialog = new EndGameDialog(new ImageIcon(System.class.getResource("/images/ganaste120x120.jpg")),logic.getModel().getPlayersNames()[0]/*+" GANO!!"*/);
                    } else {
                        endGameDialog = new EndGameDialog(new ImageIcon(System.class.getResource("/images/ganaste120x120.jpg")),logic.getModel().getPlayersNames()[1]/*+" GANO!!"*/);
                    }
                } else {
                    if (logic.getModel().getPlayersColors()[0]==ReversiToken.BLACK) {
                        endGameDialog = new EndGameDialog(new ImageIcon(System.class.getResource("/images/ganaste120x120.jpg")),logic.getModel().getPlayersNames()[0]/*+" GANO!!"*/);
                    } else {
                        endGameDialog = new EndGameDialog(new ImageIcon(System.class.getResource("/images/ganaste120x120.jpg")),logic.getModel().getPlayersNames()[1]/*+" GANO!!"*/);
                    }
                }
            }   
        }
        logic.getModel().getGui().setEnabled(false);
        logic.getModel().getGui().setFocusable(false);
        endGameDialog.setFather(logic.getModel().getGui());
        endGameDialog.setVisible(true);
    }
    
    public void setSettingsEnabled(boolean enable) {
        this.settingsMenuItem.setEnabled(enable);
    }

}
